package com.jinmdz.fmis.api.admin.controller;

import com.jinmdz.fmis.api.admin.model.administrativearea.AdministrativeAreaIdData;
import com.jinmdz.fmis.api.admin.model.administrativearea.AdministrativeAreaParentIdData;
import com.jinmdz.fmis.api.admin.model.administrativearea.AdministrativeAreaSaveData;
import com.jinmdz.fmis.api.admin.model.administrativearea.AdministrativeAreaTreeItem;
import com.jinmdz.fmis.api.admin.service.AdministrativeAreaService;
import com.jinmdz.fmis.api.api.model.common.IdData;
import com.jinmdz.fmis.api.api.model.common.IdVersionData;
import com.jinmdz.fmis.api.base.BaseController;
import com.jinmdz.fmis.core.base.BaseResult;
import com.jinmdz.fmis.core.model.SearchLoadData;
import com.jinmdz.fmis.dao.admin.model.administrativearea.AdministrativeAreaListItem;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;


/**
 * 行政区划维护信息相关接口
 *
 * @author LiCongLu
 * @date 2020-03-15 20:01
 */
@Api(description = "行政区划维护信息相关接口")
@RestController()
@RequestMapping("/admin/administrative-area")
public class AdministrativeAreaController extends BaseController {

    @Resource
    private AdministrativeAreaService administrativeAreaService;

    /**
     * 区划树，根据行政区划父节点parent_id加载表【system_area】中保存的子行政区划数据
     *
     * @param data 父主键
     * @return
     * @author LiCongLu
     * @date 2020-03-15 20:01
     */
    @ApiOperation(value = "区划树，根据行政区划父节点parent_id加载表【system_area】中保存的子行政区划数据", notes = "区划树，根据表【system_area】中父行政区划parent_id加载表【system_area】中保存的子行政区划数据")
    @PostMapping("/load-administrative-area-tree-with-parent-id")
    public BaseResult<ArrayList<AdministrativeAreaTreeItem>>  loadAdministrativeAreaTreeWithParentId(@RequestBody IdData data) {
        return resultHandler(userItem -> administrativeAreaService.loadAdministrativeAreaTreeWithParentId(data));
    }

    /**
     * 根据行政区划父节点parent_id加载表【system_area】中保存的子行政区划数据
     *
     * @param data 父主键信息
     * @return
     * @author LiCongLu
     * @date 2020-03-15 20:01
     */
    @ApiOperation(value = "根据行政区划父节点parent_id加载表【system_area】中保存的子行政区划数据", notes = "根据表【system_area】中父行政区划parent_id加载表【system_area】中保存的子行政区划数据")
    @PostMapping("/load-administrative-area-list-with-parent-id")
    public BaseResult<SearchLoadData<AdministrativeAreaListItem>> loadAdministrativeAreaListWithParentId(@RequestBody AdministrativeAreaParentIdData data) {
        return resultHandler(userItem -> administrativeAreaService.loadAdministrativeAreaListWithParentId(data));
    }

    /**
     * 加载行政区划信息
     *
     * @param data 主键
     * @return
     * @author LiCongLu
     * @date 2020-03-15 20:01
     */
    @ApiOperation(value = "根据【system_area】表中id加载行政区划信息", notes = "根据ID加载行政区划信息")
    @PostMapping("/load-administrative-area-with-id")
    public BaseResult<AdministrativeAreaSaveData> loadAdministrativeAreaWithId(@RequestBody AdministrativeAreaIdData data) {
        return resultHandler(data, userItem -> administrativeAreaService.loadAdministrativeAreaWithId(data));
    }

    /**
     * 保存行政区划信息到system_area表中
     *
     * @param data 行政区划请求数据
     * @return
     * @author LiCongLu
     * @date 2020-03-15 20:01
     */
    @ApiOperation(value = "保存行政区划信息到【system_area】表中", notes = "保存行政区划信息到【system_area】表中")
    @PostMapping("/save-administrative-area")
    public BaseResult saveAdministrativeArea(@RequestBody AdministrativeAreaSaveData data) {
        return resultHandler(data, userItem -> administrativeAreaService.saveAdministrativeArea(userItem, data));
    }

    /**
     * 从system_area表中删除指定id的行政区划信息记录
     *
     * @param data 主键和版本号
     * @return
     * @author LiCongLu
     * @date 2020-03-15 20:01
     */
    @ApiOperation(value = "从system_area表中删除指定id的行政区划信息记录", notes = "从system_area表中删除指定id的行政区划信息")
    @PostMapping("/delete-administrative-area-with-id")
    public BaseResult deleteAdministrativeAreaWithId(@RequestBody ArrayList<IdVersionData> data) {
        return resultHandler(data, userItem -> administrativeAreaService.deleteAdministrativeAreaWithId(userItem, data));
    }
}
